package com.xmb.wechat.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.blankj.utilcode.util.ScreenUtils;
import com.xmb.wechat.R;
import com.xmb.wechat.bean.WechatContactBean;
import com.xmb.wechat.definterface.OnChooseRoleListener;

import java.util.Objects;

/**
 * @Author lijiangop
 * @CreateTime 2020/3/25 16:47
 */
public class RoleChooseDialog extends Dialog {

    private WechatContactBean  mineContactBean;
    private ImageView          mIvMine;
    private LinearLayout       mLlMmine;

    public RoleChooseDialog(@NonNull Context context, OnChooseRoleListener whoSendListener) {
        super(context, R.style.PopupDialog);
        initView(context, whoSendListener);
    }

    private void initView(Context context, OnChooseRoleListener chooseWhoListener) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_role_choose, null, false);
        mLlMmine = view.findViewById(R.id.ll_mine);
        mLlMmine.setOnClickListener(v -> {
            if (chooseWhoListener != null)
                chooseWhoListener.onMeChoose(mineContactBean);
            dismiss();
        });
        view.findViewById(R.id.ll_other).setOnClickListener(v -> {
            if (chooseWhoListener != null)
                chooseWhoListener.onOtherChoose();
            dismiss();
        });
        view.findViewById(R.id.ll_edit).setOnClickListener(v -> {
            if (chooseWhoListener != null)
                chooseWhoListener.onNewAdd();
            dismiss();
        });
        mIvMine = view.findViewById(R.id.iv_mine);
        setContentView(view);
        WindowManager.LayoutParams lp = Objects.requireNonNull(getWindow()).getAttributes();
        lp.width = ScreenUtils.getScreenWidth();
        lp.dimAmount = 0.5f;
        lp.gravity = Gravity.BOTTOM;
        getWindow().setAttributes(lp);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }

    public void setMineValue(WechatContactBean senderContactBean) {
        mineContactBean = senderContactBean;
        //        if (senderContactBean == null)
        //            return;
        //        if (mIvMine == null)
        //            return;
        //        if (TextUtils.isEmpty(senderContactBean.getAvatar()))
        //            Picasso.get().load(R.drawable.ic_wx_default_avatar).transform(new PicassoCircularTransform()).into(mIvMine);
        //        else
        //            Picasso.get().load("file://" + senderContactBean.getAvatar()).error(R.drawable.ic_wx_default_avatar).transform(new PicassoCircularTransform()).into(mIvMine);
    }

    public void hideMe() {
        if (mLlMmine != null)
            mLlMmine.setVisibility(View.GONE);
    }
}
